/**
 * 
 */
package com.daily.expenses;

import android.content.Context;
import android.content.Intent;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;
import android.widget.DatePicker;
import android.widget.Toast;

/**
 * @author No3x
 * 
 */
public class Record implements Parcelable {
	private static final String LOG_BREADCRUMB = "Record";

	private long Id;
	private String Title;
	private String Description;
	private double amount;
	private int Date_Year;
	private int Date_Month;
	private int Date_Day;

	public Record() {

	}

	public long getId() {
		return Id;
	}

	public void setId(long id) {
		this.Id = id;
	}

	public String getTitle() {
		return Title;
	}

	public void setTitle(String title) {
		if (title.isEmpty()) {
			Log.e(LOG_BREADCRUMB, "Title is empty! Ignore changes.");
		} else {
			this.Title = title;
		}
	}

	public String getDescription() {
		return Description;
	}

	public void setDescription(String description) {
		Description = description;
	}

	public double getAmount() {
		return amount;
	}

	public void setAmount(double amount) {
		this.amount = amount;
	}

	// Will be used by the ArrayAdapter in the ListView
	@Override
	public String toString() {
		return Title;
	}

	public void setDate(DatePicker datePicker) {
		this.setDate_Year(datePicker.getYear());
		this.setDate_Month(datePicker.getMonth());
		this.setDate_Day(datePicker.getDayOfMonth());
	}

	public void setDate(int year, int month, int dayOfMonth) {
		this.setDate_Year(year);
		this.setDate_Month(month);
		this.setDate_Day(dayOfMonth);
	}

	public int getDate_Year() {
		return Date_Year;
	}

	public void setDate_Year(int date_Year) {
		Date_Year = date_Year;
	}

	public int getDate_Month() {
		return Date_Month;
	}

	public void setDate_Month(int date_Month) {
		Date_Month = date_Month;
	}

	public int getDate_Day() {
		return Date_Day;
	}

	public void setDate_Day(int date_Day) {
		Date_Day = date_Day;
	}

	protected Record(Parcel in) {
		Id = in.readLong();
		Title = in.readString();
		Description = in.readString();
		amount = in.readDouble();
		Date_Year = in.readInt();
		Date_Month = in.readInt();
		Date_Day = in.readInt();
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeLong(Id);
		dest.writeString(Title);
		dest.writeString(Description);
		dest.writeDouble(amount);
		dest.writeInt(Date_Year);
		dest.writeInt(Date_Month);
		dest.writeInt(Date_Day);
	}

	public static final Parcelable.Creator<Record> CREATOR = new Parcelable.Creator<Record>() {
		public Record createFromParcel(Parcel in) {
			return new Record(in);
		}

		public Record[] newArray(int size) {
			return new Record[size];
		}
	};

	/* Debug functions */
	public void printRecordtoLog(String breadcrumb) {
		Log.d(breadcrumb, "--Record:--");
		Log.d(breadcrumb, "Id: " + this.Id);
		Log.d(breadcrumb, "Title: " + this.Title);
		Log.d(breadcrumb, "Description: " + this.Description);
		Log.d(breadcrumb, "amount: " + this.amount);
		Log.d(breadcrumb, "Date_Year: " + this.Date_Year);
		Log.d(breadcrumb, "Date_Month: " + this.Date_Month);
		Log.d(breadcrumb, "Date_Day: " + this.Date_Day);
		Log.d(breadcrumb, "--Record end--");
	}
}
